package xyz.robinbingo.leetcode.a20.b06.c26;

import xyz.robinbingo.leetcode.ListNode;

public class Solution {
    public ListNode removeDuplicateNodes(ListNode head) {
        if (head == null) {
            return null;
        }
        remove(head);
        return head;
    }

    private void remove(ListNode node) {
        if (node == null) {
            return;
        }
        removeIt(node, node.val);
        remove(node.next);
    }


    private void removeIt(ListNode node, int val) {
        if (node == null || node.next == null) {
            return;
        }
        ListNode next = node.next;
        if (next.val == val) {
            node.next = next.next;
            removeIt(node, val);
        } else {
            removeIt(node.next, val);
        }

    }
}